package com.ethank.enums;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 阿里发票识别错误返回枚举
 *
 * @author Administrator
 */

public enum AliBillEnum {
    ALGORITHMERROR("503", "algorithmError", "识别服务异常，请稍后重试"),
    ALGORITHMTIMEOUT("503", "AlgorithmTimeout", "算法服务不可用，请尝试内容较少的图像"),
    CONVERTPDFTOIMGERROR("400", "convertPDFToImgError", "pdf转图片失败"),
    DEPRECATEDAPI("400", "deprecatedApi", "此API已经废弃，请使用新版本的API"),
    EXCEEDEDFACEBACKCOUNT("400", "ExceededFaceBackCount", "图片正反面数量超过了限制"),
    EXCEEDEDIMAGECONTENT("413", "exceededImageContent", "图像内容大小超过 10M"),
    EXCEEDEDIMAGEURLLENGTH("400", "exceededImageUrlLength", "图片 URL 长度超过2048"),
    EXCEEDEDPDFCONTENT("413", "exceededPDFContent", "PDF大小超过10M"),
    ILLEGALAPINAME("400", "illegalApiName", "API名称出错"),
    ILLEGALCUTTYPE("400", "illegalCutType", "不支持的 cutType 参数"),
    ILLEGALIMAGECONTENT("400", "illegalImageContent", "缺少对应的图像内容，导致切图失败"),
    ILLEGALIMAGESIZE("416", "illegalImageSize", "图像尺寸不合法"),
    ILLEGALIMAGETYPE("400", "illegalImageType", "不支持的 imageType 参数"),
    ILLEGALIMAGEURL("400", "IllegalImageUrl", "图片 URL 资源不可用或超时"),
    ILLEGALPDFCONTENT("400", "illegalPDFContent", "PDF内容缺失或不是有效的PDF文件"),
    ILLEGALSIGNATURE("400", "illegalSignature", "签名错误"),
    ILLEGALSUBJECT("400", "illegalSubject", "不支持的 subject（科目） 参数"),
    IMAGETIMEOUT("400", "imageTimeOut", "获取图片超时"),
    IMAGEURLOREMPTY("400", "imageUrlOrBodyEmpty", "图片URL或BODY为空"),
    INVALIDCOUNTRY("400", "InvalidCountry", "不支持的国家"),
    INVALIDINPUTPARAMETER("400", "invalidInputParameter", "输入的参数无效"),
    INVALIDSIGNATUREVERSSION("400", "InvalidSignatureVerssion", "签名版本错误"),
    INVALIDSTSTOKEN("400", "invalidStsToken", "STS token 错误"),
    INVALIDVERSION("400", "InvalidVersion", "参数版本错误"),
    MISSINGACCESSKEYID("400", "MissingAccessKeyId", "缺少AccessKeyId"),
    MISSINGIMAGENAME("400", "missingImageName", "必须输入图片名字"),
    MISSINGIMAGETYPE("400", "MissingImageType", "缺少图片类型"),
    MISSINGIMAGEURL("400", "MissingImageUrl", "图片URL为空"),
    MISSINGLANGUAGES("400", "MissingLanguages", "缺少 language 参数"),
    MISSINGSIGNATURE("400", "MissingSignature", "缺少签名"),
    NOPERMISSION("401", "noPermission", "子账号或角色未授权"),
    NOTSAFEIMAGEURL("400", "notSafeImageUrl", "图片 URL 不安全"),
    OCRSERVICEEXPIRED("401", "OcrServiceExpired", "OCR服务已经欠费过期"),
    OCRSERVICENOTOPEN("401", "ocrServiceNotOpen", "OCR服务未开通"),
    PAPERCUTEMPTYIMAGE("400", "PaperCutEmptyImage", "在用于切题的图像中没有找到任何试卷，请检查图像"),
    SERVICETIMEOUT("504", "ServiceTimeout", "后端服务超时"),
    SERVICEUNAVAILABLE("503", "ServiceUnavailable", "服务器错误"),
    SIGNATUREDOESNOTMATCH("400", "SignatureDoesNotMatch", "签名错误"),
    SIGNATURENONCEUSED("400", "SignatureNonceUsed", "Signature nonce已经被使用"),
    SYSTEMERROR("500", "systemError", "服务器异常，请稍后重试"),
    THROTTLINGUSER("429", "Throttling.User", "超过限流阈值"),
    UNMATCHEDIMAGETYPE("400", "unmatchedImageType", "图像类型与API接口不匹配"),
    UNSUPPORTEDENCODEIMAGEURL("400", "unsupportedEncodeImageUrl", "图片 URL 编码无法解析"),
    UNSUPPORTEDIMAGEFORMAT("415", "unsupportedImageFormat", "图像内容错误或格式不支持"),
    UNSUPPORTEDLANGUAGE("400", "unsupportedLanguage", "不支持的 language 参数");


    private String statusCode;
    private String code;
    private String message;
    AliBillEnum() {
    }

    AliBillEnum(String statusCode, String code, String message) {
        this.statusCode = statusCode;
        this.code = code;
        this.message = message;
    }

    /**
     * 根据statusCode获取code列表，根绝code值获取message
     *
     * @param statusCode 状态码
     * @param code       状态类型
     * @return 提示信息
     */
    public static String getMessageByStatusCodeAndCode(String statusCode, String code) {
        List<AliBillEnum> matchedEnums = Arrays.stream(AliBillEnum.values())
                .filter(e -> e.getStatusCode().equals(statusCode))
                .collect(Collectors.toList());

        for (AliBillEnum e : matchedEnums) {
            if (e.getCode().equals(code)) {
                return e.getMessage();
            }
        }

        return null;
    }

    public String getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(String statusCode) {
        this.statusCode = statusCode;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
